assists = function() {
	//定义添加修改窗体
	var ASSISTADDOREDITWIN = null;
	//定义CKEDITR组件
	//var ASSISTCKEDITTXTCOM = null;
	return {
		/*--------------------------------------窗体定义--------------------------------------------*/
		//定义GRID窗体
		panel: function() {
			var store = new Store({
				fields: ['id', 'title', 'titleImg', 'updateDate', 'txt'],
				proxy: {
			        type: 'ajax',
			        url: '../admin/assist.do?index'
			    },
			    autoLoad: true
			});
						
			var grid = new Grid({
				title: '帮助栏目列表',
				id: 'assistgrid',
				region: 'center',
				store: store,
				minColumnWidth: 35,
				stripeRows: true,
				tbar: [{
					text: '刷新',
					scale: 'medium',
					iconCls: 'icon-refresh',
					handler: function() {
						store.load();
					}
				}, "-", {
					id: 'assistEdit',
					text: '修改',
					scale: 'medium',
					iconCls: 'icon-edit',
					disabled: true,
					handler: function() {
						assists.editAction();
					}
				}],
				columns: [
		             new Ext.grid.RowNumberer(),
		             {header: '序号', dataIndex: 'id', hidden: true},
		             {header: '标题', dataIndex: 'title',width: 200},
		             {header: '更新时间', dataIndex: 'updateDate', width: 200}
				]
			});
			
			var panel = new Panel({
				border: false,
				layout: 'border',
				items: [grid]
			});
			
			return panel;
		},
		
		//定义添加修改窗体
		addOrEditWin: function() {
			if (ASSISTADDOREDITWIN == null) {
				ASSISTADDOREDITWIN = new Window({
					id: 'assistAddOrEditWin',
				    title: '帮助栏目信息编辑',
				    height: 550,
				    width: 1000,
				    layout: 'fit',
				    closeAction: "hide",
				    modal: true,
				    items: [{
				    	xtype: 'form',
				    	frame: false,
						autoHeight: true,
						autoScroll: true,
						bodyPadding: 15,
						fieldDefaults: {
				            labelWidth: 75
				        },
				        defaultType: 'textfield',
				        defaults: {
				            anchor: '95%'
				        },
				        items: [{
				        	name: 'id',
				        	hidden: true
				        }, {
				        	fieldLabel: '标题',
				        	name: 'title',
				            allowBlank: false
				        }, {
				        	fieldLabel: '标题图片',
		    				readOnly: true,
		    				name: 'titleImg'
		    			}, {
		    				xtype: 'filefield',
		    				style: 'margin-left: 80px',
		    				name: 'filepic',
		    				buttonText: '选择'
		    			}, {
		    				fieldLabel: '内容',
				        	xtype: 'textareafield',
				    		name: 'txt',
				    		height: 200,
				    		maxLength: 135
//				    			,
//				    		hidden: true
				        }
//		    			, {
//				    		xtype: 'fieldcontainer',
//				            fieldLabel: '内容',
//				            layout: 'fit',
//				            height: 330,
//				            items: [{
//				    	    	xtype: 'panel',
//				    	    	border: false,
//				    	    	html: '<textarea id="_assistfomtxt" class="ckeditor" name="_assistfomtxt"></textarea>',
//				    	    	height: 330
//				    		}]
//				        }
		    			],
				        buttons: [{
				        	text: '确定',
				        	handler: function() {
				        		var fom = this.up('form').getForm();
				        		if (fom.isValid()) {
				        			//fom.findField('txt').setValue(ASSISTCKEDITTXTCOM.getData());
				        			assists.sumbitAction(fom);
				        		}
				        	}
				        }, {
				        	text: '取消',
				        	handler: function() {
				        		ASSISTADDOREDITWIN.hide();
				        	}
				        }],
				        listeners: {
				        	afterrender: function() {
//				        		ASSISTCKEDITTXTCOM = CKEDITOR.replace('_assistfomtxt');
				        	},
				        	beforedestroy: function() {
//				        		ASSISTCKEDITTXTCOM.destory();
				        	}
				        }
				    }],
			        listeners: {
			        	hide: function(fn, eOpts) {
			        		this.down('form').getForm().reset();
//			        		ASSISTCKEDITTXTCOM.setData('');
			        	}
			        }
				});
			}
			ASSISTADDOREDITWIN.show();
		},
		
		/*--------------------------------------事件定义--------------------------------------------*/
		//修改窗体事件
		editAction: function() {
			var sel = Ext.getCmp('assistgrid').getSelectionModel().getSelection();
			if (sel.length < 1) {
				Ext.Msg.alert('提示', '请选择要修改的信息！');
			} else {
				assists.addOrEditWin();
				var fom = Ext.getCmp('assistAddOrEditWin').down('form').getForm();
				fom.loadRecord(sel[0]);
//				ASSISTCKEDITTXTCOM.setData(fom.findField('txt').value);
			}
		},
		
		//提交确认事件
		sumbitAction: function(fom) {
			var url = '../admin/assist.do?edit';
			var id = fom.findField('id').value;
			if (id == '') {
				url = '../admin/assist.do?add';
			}
			FormSubmit(fom, url, {}, function(obj) {
				Ext.getCmp('assistgrid').getStore().load();
				ASSISTADDOREDITWIN.hide();
			});
		}
	};
}();